/**
 * 
 */
package com.gragra.nounIdentification.tests;
import static org.junit.Assert.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import org.junit.Before;
import org.junit.Test;
import com.gragra.data.Corpus;
import com.gragra.nounIdentification.ConvergenceByIterations;
import com.gragra.nounIdentification.ExtendingNounIdentifier;
import com.gragra.nounIdentification.IncreasingMaxWithMin;
import com.gragra.nounIdentification.LinearIncreasingMax;
import com.gragra.nounIdentification.TypesPerTokenScorer;
import com.gragra.sampling.sequentialStructure.ExtensionLevels;
import com.gragra.sampling.sequentialStructure.WordAndTagHolder;
import com.gragra.sampling.sequentialStructure.WordType;
import com.gragra.sequentiaDataGenerator.BaseGenerator;
import com.gragra.sequentiaDataGenerator.CaseLevelAssigningSegmenter;
import com.gragra.sequentiaDataGenerator.PunctuationSplitOffSegmenter;
/**
 * @author Christoph Teichmann
 * created Jun 8, 2013 5:46:01 PM
 * @version 0.1
 */
public class TestExtendingNounIdentifier
{
	
	/**
	 * 
	 */
	private ExtendingNounIdentifier ni;
	/**
	 *
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception
	{
		StringReader sr = new StringReader("A|NONE|ContextTagLevel|0 Cat|1|ContextTagLevel|1 is|0|ContextTagLevel|2 on|NONE|ContextTagLevel|3 the|0|ContextTagLevel|0 mat|x there.|NONE\nA|g|ContextTagLevel|0 horse|NONE|ContextTagLevel|1 is|0 on|NONE the|0 grass|c there.|NONE\n" +
				"A|NONE|ContextTagLevel|0 stain|1|ContextTagLevel|1 is|0|ContextTagLevel|2 on|NONE|ContextTagLevel|3 the|0|ContextTagLevel|0 mat.|NONE\nA|g|ContextTagLevel|0 ball|NONE|ContextTagLevel|1 is|0 on|NONE the|0 grass.|NONE");
		BufferedReader br = new BufferedReader(sr);
		BaseGenerator bg = new BaseGenerator(new CaseLevelAssigningSegmenter(new PunctuationSplitOffSegmenter("NONE")));
		Corpus<WordAndTagHolder>  corp = bg.createCorpus(br);
		ni = new ExtendingNounIdentifier(corp, 3, 0, 0, new TypesPerTokenScorer(),new ConvergenceByIterations(2), new IncreasingMaxWithMin(new LinearIncreasingMax(1, 1), 2, 6),2);
		ni.identify();
	}
	/**
	 * Test method for {@link com.gragra.nounIdentification.ExtendingNounIdentifier#annotateCorpusFrames(com.gragra.data.Corpus)}.
	 * @throws IOException 
	 */
	@Test
	public final void testAnnotateCorpusFrames() throws IOException
	{
		StringReader sr = new StringReader("A|NONE|ContextTagLevel|0 Cat|1|ContextTagLevel|1 is|0|ContextTagLevel|2 on|NONE|ContextTagLevel|3 the|0|ContextTagLevel|0 mat.|NONE\nA|g|ContextTagLevel|0 horse|NONE|ContextTagLevel|1 is|0|ContextTagLevel|1 on|NONE the|0 grass.|NONE");
		BufferedReader br = new BufferedReader(sr);
		BaseGenerator bg = new BaseGenerator(new CaseLevelAssigningSegmenter(new PunctuationSplitOffSegmenter("NONE")));
		Corpus<WordAndTagHolder> corp = bg.createCorpus(br);
		ni.annotateCorpusFrames(corp);
		assertTrue(corp.getEntry(0).getExtensionInformation().getFiniteInformation(0, ExtensionLevels.WordTypeLevel)==null);
		assertTrue(corp.getEntry(1).getExtensionInformation().getFiniteInformation(2, ExtensionLevels.WordTypeLevel)==WordType.Noun);
	}
	/**
	 * Test method for {@link com.gragra.nounIdentification.ExtendingNounIdentifier#evaluate(com.gragra.data.Corpus, boolean)}.
	 * @throws IOException 
	 */
	@Test
	public final void testEvaluate() throws IOException
	{
		StringReader sr = new StringReader("A|NONE|ContextTagLevel|0|WordTypeLevel|Noun Cat|1|ContextTagLevel|1|WordTypeLevel|Noun is|0|ContextTagLevel|2 on|NONE|ContextTagLevel|3 the|0|ContextTagLevel|0 mat.|NONE\nA|g|ContextTagLevel|0 horse|NONE|ContextTagLevel|1 is|0|ContextTagLevel|1|WordTypeLevel|Noun on|NONE the|0 grass.|NONE");
		BufferedReader br = new BufferedReader(sr);
		BaseGenerator bg = new BaseGenerator(new CaseLevelAssigningSegmenter(new PunctuationSplitOffSegmenter("NONE")));
		Corpus<WordAndTagHolder> corp = bg.createCorpus(br);
		assertEquals(java.util.Arrays.toString(ni.evaluate(corp, true)),"[0.6666666666666666, 0.6666666666666666, 0.6666666666666666]");
	}
}